<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="课表ID" prop="scheduleId">
        <el-input
          v-model="queryParams.scheduleId"
          placeholder="请输入课表ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="教学计划内容ID" prop="contentId">
        <el-input
          v-model="queryParams.contentId"
          placeholder="请输入教学计划内容ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="上课日期" prop="scheduleDate">
        <el-date-picker clearable size="small" style="width: 200px"
          v-model="queryParams.scheduleDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择上课日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="星期几" prop="weekDay">
        <el-input
          v-model="queryParams.weekDay"
          placeholder="请输入星期几"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="上课时段" prop="scheduleSegment">
        <el-input
          v-model="queryParams.scheduleSegment"
          placeholder="请输入上课时段"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="调课标识" prop="changeFlag">
        <el-input
          v-model="queryParams.changeFlag"
          placeholder="请输入调课标识"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="代课标识" prop="takeFlag">
        <el-input
          v-model="queryParams.takeFlag"
          placeholder="请输入代课标识"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="教师ID" prop="teachUserId">
        <el-input
          v-model="queryParams.teachUserId"
          placeholder="请输入教师ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="代课教师ID" prop="takeUserId">
        <el-input
          v-model="queryParams.takeUserId"
          placeholder="请输入代课教师ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['edu:scheduleInfo:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['edu:scheduleInfo:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['edu:scheduleInfo:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['edu:scheduleInfo:export']"
        >导出</el-button>
      </el-col>
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="scheduleInfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="课表详情ID" align="center" prop="scheduleInfoId" />
      <el-table-column label="课表ID" align="center" prop="scheduleId" />
      <el-table-column label="教学计划内容ID" align="center" prop="contentId" />
      <el-table-column label="上课日期" align="center" prop="scheduleDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.scheduleDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="星期几" align="center" prop="weekDay" />
      <el-table-column label="上课时段" align="center" prop="scheduleSegment" />
      <el-table-column label="调课标识" align="center" prop="changeFlag" />
      <el-table-column label="代课标识" align="center" prop="takeFlag" />
      <el-table-column label="教师ID" align="center" prop="teachUserId" />
      <el-table-column label="代课教师ID" align="center" prop="takeUserId" />
      <el-table-column label="班主任备注" align="center" prop="masterRemark" />
      <el-table-column label="教师备注" align="center" prop="teacherRemark" />
      <el-table-column label="状态" align="center" prop="status" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['edu:scheduleInfo:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['edu:scheduleInfo:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改班级科目排课详情对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="课表ID" prop="scheduleId">
          <el-input v-model="form.scheduleId" placeholder="请输入课表ID" />
        </el-form-item>
        <el-form-item label="教学计划内容ID" prop="contentId">
          <el-input v-model="form.contentId" placeholder="请输入教学计划内容ID" />
        </el-form-item>
        <el-form-item label="上课日期" prop="scheduleDate">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.scheduleDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择上课日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="星期几" prop="weekDay">
          <el-input v-model="form.weekDay" placeholder="请输入星期几" />
        </el-form-item>
        <el-form-item label="上课时段" prop="scheduleSegment">
          <el-input v-model="form.scheduleSegment" placeholder="请输入上课时段" />
        </el-form-item>
        <el-form-item label="调课标识" prop="changeFlag">
          <el-input v-model="form.changeFlag" placeholder="请输入调课标识" />
        </el-form-item>
        <el-form-item label="代课标识" prop="takeFlag">
          <el-input v-model="form.takeFlag" placeholder="请输入代课标识" />
        </el-form-item>
        <el-form-item label="教师ID" prop="teachUserId">
          <el-input v-model="form.teachUserId" placeholder="请输入教师ID" />
        </el-form-item>
        <el-form-item label="代课教师ID" prop="takeUserId">
          <el-input v-model="form.takeUserId" placeholder="请输入代课教师ID" />
        </el-form-item>
        <el-form-item label="班主任备注" prop="masterRemark">
          <el-input v-model="form.masterRemark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="教师备注" prop="teacherRemark">
          <el-input v-model="form.teacherRemark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="状态">
          <el-radio-group v-model="form.status">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="删除标志" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入删除标志" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" type="primary" @click="submitForm">确 定</el-button>
        <el-button size="mini" @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listScheduleInfo, getScheduleInfo, delScheduleInfo, addScheduleInfo, updateScheduleInfo, exportScheduleInfo } from "@/api/edu/scheduleInfo";

export default {
  name: "ScheduleInfo",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 班级科目排课详情表格数据
      scheduleInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        scheduleId: null,
        contentId: null,
        scheduleDate: null,
        weekDay: null,
        scheduleSegment: null,
        changeFlag: null,
        takeFlag: null,
        teachUserId: null,
        takeUserId: null,
        masterRemark: null,
        teacherRemark: null,
        status: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        scheduleId: [
          { required: true, message: "课表ID不能为空", trigger: "blur" }
        ],
        contentId: [
          { required: true, message: "教学计划内容ID不能为空", trigger: "blur" }
        ],
        teachUserId: [
          { required: true, message: "教师ID不能为空", trigger: "blur" }
        ],
        takeUserId: [
          { required: true, message: "代课教师ID不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询班级科目排课详情列表 */
    getList() {
      this.loading = true;
      listScheduleInfo(this.queryParams).then(response => {
        this.scheduleInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        scheduleInfoId: null,
        scheduleId: null,
        contentId: null,
        scheduleDate: null,
        weekDay: null,
        scheduleSegment: null,
        changeFlag: null,
        takeFlag: null,
        teachUserId: null,
        takeUserId: null,
        masterRemark: null,
        teacherRemark: null,
        status: "0",
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.scheduleInfoId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加班级科目排课详情";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const scheduleInfoId = row.scheduleInfoId || this.ids
      getScheduleInfo(scheduleInfoId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改班级科目排课详情";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.scheduleInfoId != null) {
            updateScheduleInfo(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addScheduleInfo(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const scheduleInfoIds = row.scheduleInfoId || this.ids;
      this.$confirm('是否确认删除班级科目排课详情编号为"' + scheduleInfoIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delScheduleInfo(scheduleInfoIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有班级科目排课详情数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportScheduleInfo(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
